package com.chexiehui.jc.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.widget.FrameLayout;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.chexiehui.jc.R;
import com.chexiehui.jc.adapter.CommVLayoutAdapter;
import com.chexiehui.jc.base.BaseFragment;
import com.chexiehui.jc.widget.CustomRoundAngleImageView;
import com.chexiehui.jc.widget.LoadingLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Author: SongJun.
 * CreateDate: 2019/1/21 0021.
 * Description: 论坛
 */

public class ForumCarVideoFragment extends BaseFragment {
    public static ForumCarVideoFragment getInstance() {
        ForumCarVideoFragment fragment = new ForumCarVideoFragment();
        return fragment;
    }

    @BindView(R.id.loadingLayout)
    LoadingLayout loadingLayout;
    @BindView(R.id.recycler)
    RecyclerView mRecycler;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    private DelegateAdapter listAdapter;

    private CommVLayoutAdapter<String> bbsAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_forum_car_video;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        loadingLayout.setStatus(LoadingLayout.Success);
        refreshLayout.setEnableRefresh(false);
        refreshLayout.setEnableLoadMore(false);
        refreshLayout.setEnableOverScrollDrag(true);
        refreshLayout.setDragRate(0.5f);

        VirtualLayoutManager virtualLayoutManager = new VirtualLayoutManager(mActivity);
        mRecycler.setLayoutManager(virtualLayoutManager);
        ((SimpleItemAnimator) mRecycler.getItemAnimator()).setSupportsChangeAnimations(false);
        final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
        mRecycler.setRecycledViewPool(viewPool);
        viewPool.setMaxRecycledViews(0, 20);
        listAdapter = new DelegateAdapter(virtualLayoutManager, false);
        mRecycler.setAdapter(listAdapter);

        GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(2);
        int dp_5 = SizeUtils.dp2px(5);
        gridLayoutHelper.setPadding(dp_5, dp_5, dp_5, dp_5);
        gridLayoutHelper.setGap(dp_5);
        gridLayoutHelper.setAutoExpand(false);
        bbsAdapter = new CommVLayoutAdapter<String>(mActivity, new ArrayList<>(),
                R.layout.item_forum_car_video, gridLayoutHelper) {
            @Override
            protected void convert(ViewHolder holder, int position, String item) {
                CustomRoundAngleImageView iv_item_image = holder.getView(R.id.iv_item_image);
                FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) iv_item_image.getLayoutParams();
                int w = (ScreenUtils.getScreenWidth() - (dp_5 * 3)) / 2;
                lp.width = w;
                lp.height = w * 280 / 176;
                iv_item_image.setLayoutParams(lp);
                Glide.with(mActivity)
                        .load("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3303252466,881739675&fm=26&gp=0.jpg")
                        .into(iv_item_image);
            }
        };
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        bbsAdapter.getData().add("");
        listAdapter.addAdapter(bbsAdapter);
    }
}
